<template>
  <div class="fuwenben">
    <div id="editor">

    </div>
  </div>
</template>

<script>
  import axios from "axios";
  import E from 'wangeditor'
  export default {
    name: "fuwenben",
    props:['description'],
    data() {
      return {

      }
    },
    created() {
      console.log(this.description)
    },
    mounted() {
      var that = this
      var editor = new E('#editor');
      editor.customConfig.uploadImgServer = '/upload'
      editor.customConfig.showLinkImg = false
      editor.customConfig.onchange = function(html) {
        that.$emit('fuwenbenfanhui',html)
      }
      editor.customConfig.customUploadImg = function(files, insert) {
      	var formData = new FormData();
      	formData.append("pic", files[0]);
      	axios.post('/api/plan-market/order-page/upload-pic', formData)
      		.then(response => {
      			if (response.data.msg.code == 0) {
      				insert(response.data.data)
      			} else {
      				that.$message.error(response.data.msg.info);
      			}
      		})
      }
      editor.create();

      
      if(that.description){
        editor.txt.html(that.description)
      }

    },
    methods: {

    }
  }
</script>

<style scoped lang="scss">
  .fuwenben {
    #editor{
      max-width: 750px;
      img{ max-width: 100%;}
      /deep/ .w-e-text-container{ min-height: 300px; }
      /deep/ .w-e-toolbar{ }
    }
  }
</style>
